// test.c  
#include <stdio.h>  
#include <string.h>  
#include <openssl/evp.h>  
#include "sm3hash.h"  

// 打印缓冲区为十六进制格式  
void dumpbuf(const unsigned char *buf, int len) {  
    for (int i = 0; i < len; i++) {  
        printf("%02x", buf[i]);  
    }  
    printf("\n");  
}  

int main(void)  
{  
    const unsigned char sample1[] = { 'a', 'b', 'c', 0 };  
    unsigned int sample1_len = strlen((const char *)sample1);  
    
    const unsigned char sample2[] = {  
        0x61, 0x62, 0x63, 0x64,   
        0x61, 0x62, 0x63, 0x64,  
        0x61, 0x62, 0x63, 0x64,   
        0x61, 0x62, 0x63, 0x64,  
        0x61, 0x62, 0x63, 0x64,   
        0x61, 0x62, 0x63, 0x64,  
        0x61, 0x62, 0x63, 0x64,   
        0x61, 0x62, 0x63, 0x64,  
        0x61, 0x62, 0x63, 0x64,   
        0x61, 0x62, 0x63, 0x64,  
        0x61, 0x62, 0x63, 0x64,   
        0x61, 0x62, 0x63, 0x64,  
        0x61, 0x62, 0x63, 0x64,   
        0x61, 0x62, 0x63, 0x64,  
        0x61, 0x62, 0x63, 0x64,   
        0x61, 0x62, 0x63, 0x64  
    };  
    unsigned int sample2_len = sizeof(sample2);  
    unsigned char hash_value[32]; // SM3 输出 32 字节  
    unsigned int hash_len;  
    int ret, i;  

    // 处理 sample1  
    ret = sm3_hash(sample1, sample1_len, hash_value, &hash_len);  
    if (ret != 0) {  
        fprintf(stderr, "SM3 Hash failed for sample1\n");  
        return 1;  
    }  
    printf("Raw data (sample1): %s\n", sample1);  
    printf("Hash length: %u bytes.\n", hash_len);  
    printf("Hash value:\n");  
    dumpbuf(hash_value, hash_len);  
    printf("\n");  

    // 处理 sample2  
    ret = sm3_hash(sample2, sample2_len, hash_value, &hash_len);  
    if (ret != 0) {  
        fprintf(stderr, "SM3 Hash failed for sample2\n");  
        return 1;  
    }  
    printf("Raw data (sample2):\n");  
    for (i = 0; i < sample2_len; i++)  
    {  
        printf("0x%x  ", sample2[i]);  
    }  
    printf("\n");  
    printf("Hash length: %u bytes.\n", hash_len);  
    printf("Hash value:\n");  
    dumpbuf(hash_value, hash_len);  
    printf("\n");  

    return 0;  
}